using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the AppSetting class.
	/// </summary>
	[Serializable]
	public partial class AppSettingCollection : ActiveList<AppSetting, AppSettingCollection> 
	{	   
		public AppSettingCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the AppSetting table.
	/// </summary>
	[Serializable]
	public partial class AppSetting : ActiveRecord<AppSetting>
	{
		#region .ctors and Default Settings
		
		public AppSetting()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public AppSetting(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public AppSetting(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public AppSetting(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("AppSetting", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarAppSettingID = new TableSchema.TableColumn(schema);
				colvarAppSettingID.ColumnName = "AppSettingID";
				colvarAppSettingID.DataType = DbType.Double;
				colvarAppSettingID.MaxLength = 0;
				colvarAppSettingID.AutoIncrement = false;
				colvarAppSettingID.IsNullable = false;
				colvarAppSettingID.IsPrimaryKey = true;
				colvarAppSettingID.IsForeignKey = false;
				colvarAppSettingID.IsReadOnly = false;
				colvarAppSettingID.DefaultSetting = @"";
				colvarAppSettingID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAppSettingID);
				
				TableSchema.TableColumn colvarMasterKey = new TableSchema.TableColumn(schema);
				colvarMasterKey.ColumnName = "MasterKey";
				colvarMasterKey.DataType = DbType.String;
				colvarMasterKey.MaxLength = 100;
				colvarMasterKey.AutoIncrement = false;
				colvarMasterKey.IsNullable = true;
				colvarMasterKey.IsPrimaryKey = false;
				colvarMasterKey.IsForeignKey = false;
				colvarMasterKey.IsReadOnly = false;
				colvarMasterKey.DefaultSetting = @"";
				colvarMasterKey.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMasterKey);
				
				TableSchema.TableColumn colvarKeyName = new TableSchema.TableColumn(schema);
				colvarKeyName.ColumnName = "KeyName";
				colvarKeyName.DataType = DbType.String;
				colvarKeyName.MaxLength = 100;
				colvarKeyName.AutoIncrement = false;
				colvarKeyName.IsNullable = true;
				colvarKeyName.IsPrimaryKey = false;
				colvarKeyName.IsForeignKey = false;
				colvarKeyName.IsReadOnly = false;
				colvarKeyName.DefaultSetting = @"";
				colvarKeyName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarKeyName);
				
				TableSchema.TableColumn colvarValueX = new TableSchema.TableColumn(schema);
				colvarValueX.ColumnName = "Value";
				colvarValueX.DataType = DbType.String;
				colvarValueX.MaxLength = 100;
				colvarValueX.AutoIncrement = false;
				colvarValueX.IsNullable = true;
				colvarValueX.IsPrimaryKey = false;
				colvarValueX.IsForeignKey = false;
				colvarValueX.IsReadOnly = false;
				colvarValueX.DefaultSetting = @"";
				colvarValueX.ForeignKeyTableName = "";
				schema.Columns.Add(colvarValueX);
				
				TableSchema.TableColumn colvarDateAdded = new TableSchema.TableColumn(schema);
				colvarDateAdded.ColumnName = "DateAdded";
				colvarDateAdded.DataType = DbType.DateTime;
				colvarDateAdded.MaxLength = 0;
				colvarDateAdded.AutoIncrement = false;
				colvarDateAdded.IsNullable = false;
				colvarDateAdded.IsPrimaryKey = false;
				colvarDateAdded.IsForeignKey = false;
				colvarDateAdded.IsReadOnly = false;
				
						colvarDateAdded.DefaultSetting = @"(getdate())";
				colvarDateAdded.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateAdded);
				
				TableSchema.TableColumn colvarDateModified = new TableSchema.TableColumn(schema);
				colvarDateModified.ColumnName = "DateModified";
				colvarDateModified.DataType = DbType.DateTime;
				colvarDateModified.MaxLength = 0;
				colvarDateModified.AutoIncrement = false;
				colvarDateModified.IsNullable = false;
				colvarDateModified.IsPrimaryKey = false;
				colvarDateModified.IsForeignKey = false;
				colvarDateModified.IsReadOnly = false;
				
						colvarDateModified.DefaultSetting = @"(getdate())";
				colvarDateModified.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateModified);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("AppSetting",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("AppSettingID")]
		public double AppSettingID 
		{
			get { return GetColumnValue<double>("AppSettingID"); }

			set { SetColumnValue("AppSettingID", value); }

		}

		  
		[XmlAttribute("MasterKey")]
		public string MasterKey 
		{
			get { return GetColumnValue<string>("MasterKey"); }

			set { SetColumnValue("MasterKey", value); }

		}

		  
		[XmlAttribute("KeyName")]
		public string KeyName 
		{
			get { return GetColumnValue<string>("KeyName"); }

			set { SetColumnValue("KeyName", value); }

		}

		  
		[XmlAttribute("ValueX")]
		public string ValueX 
		{
			get { return GetColumnValue<string>("Value"); }

			set { SetColumnValue("Value", value); }

		}

		  
		[XmlAttribute("DateAdded")]
		public DateTime DateAdded 
		{
			get { return GetColumnValue<DateTime>("DateAdded"); }

			set { SetColumnValue("DateAdded", value); }

		}

		  
		[XmlAttribute("DateModified")]
		public DateTime DateModified 
		{
			get { return GetColumnValue<DateTime>("DateModified"); }

			set { SetColumnValue("DateModified", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(double varAppSettingID,string varMasterKey,string varKeyName,string varValueX,DateTime varDateAdded,DateTime varDateModified)
		{
			AppSetting item = new AppSetting();
			
			item.AppSettingID = varAppSettingID;
			
			item.MasterKey = varMasterKey;
			
			item.KeyName = varKeyName;
			
			item.ValueX = varValueX;
			
			item.DateAdded = varDateAdded;
			
			item.DateModified = varDateModified;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(double varAppSettingID,string varMasterKey,string varKeyName,string varValueX,DateTime varDateAdded,DateTime varDateModified)
		{
			AppSetting item = new AppSetting();
			
				item.AppSettingID = varAppSettingID;
				
				item.MasterKey = varMasterKey;
				
				item.KeyName = varKeyName;
				
				item.ValueX = varValueX;
				
				item.DateAdded = varDateAdded;
				
				item.DateModified = varDateModified;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string AppSettingID = @"AppSettingID";
			 public static string MasterKey = @"MasterKey";
			 public static string KeyName = @"KeyName";
			 public static string ValueX = @"Value";
			 public static string DateAdded = @"DateAdded";
			 public static string DateModified = @"DateModified";
						
		}

		#endregion
	}

}

